#include "sys.h"

bit getTempflag = 0,flag500ms;flag200ms;
u8 get_temp_freq = 1;
char TempBuff[10] = {0};
char timeBuff[3] = {0};
char Temp;
void main(void)
{
	u8 index;
	All_Init();
	Timer0Init();
	Ds1302_Init();
	Get_Time(&timeBuff);
	while(1)
	{
		if(showMode == 1)
		{
			if(getTempflag)
			{
				if(Start_Ds18B20())
				{	
					TempBuff[index] = Read_Temp();
					if(TempBuff[index] == 85)
					{
					}else{
						index++;
					}
					
				}
				getTempflag = 0;
				if(index == 10)
				{
					index = 0;
					showMode = 2;
				}				
			}
			
		}
		if(showMode == 2)
		{
			if(flag500ms)
			{
				Led_Illume(0xfe);
			}else{
				Led_Illume(0xff);
			}
		}
		if(flag200ms)
		{
			flag200ms = 0;
			Get_Time(&timeBuff);
		}
		show();
		key_action();
	}
}


void Timer0() interrupt 1
{
	static u16 T0_count1;
	static u16 T0_count2;
	static u16 T0_count3;
	T0_count1++;
	T0_count2++;
	T0_count3++;
	if(T0_count1 == get_temp_freq*1000)
	{
		T0_count1 = 0;
		getTempflag = 1;
	}
	if(T0_count2 == 500)
	{
		T0_count2 = 0;
		flag500ms = ~flag500ms;
	}
	if(T0_count3 == 400)
	{
		T0_count3 = 0;
		flag200ms = 1;
	}
	Nixie_Scan();
	Nixie_Show();
}